﻿//
// Created by Freeman on 2022/2/9.
//

/**
 * 排序问题
 */

#ifndef PAT_EXERCISES_SORTING_H
#define PAT_EXERCISES_SORTING_H

#include <string>

class PAT_A1025 {
    class Candidate {
    public:
        std::string registrationNumber;
        int locationNumber;
        int score;
        int finalRank = 0;
        int localRank = 0;

    public:
        Candidate(std::string registrationNumber, int locationNumber, int score) :
                registrationNumber(std::move(registrationNumber)), locationNumber(locationNumber), score(score) {}

        static bool comp(const Candidate& oA, const Candidate& oB);
    };

public:
    static void solve();
};

class PAT_A1062 {
public:
    class Student {
    public:
        std::string admissionNumber;
        int virtueGrade, talentGrade;

    public:
        Student(std::string admissionNumber, int virtueGrade, int talentGrade) : admissionNumber(std::move(admissionNumber)),
                                                                            virtueGrade(virtueGrade),
                                                                            talentGrade(talentGrade) {}

        static bool comp(const Student &sA, const Student &sB);
    };

    static void solve();
};

class PAT_A1012 {
public:
    class Rank {
    public:
        std::string code;
        int priority;
        int value;

    public:
        static bool comp(const Rank &rankA, const Rank &rankB);
    };

    class Student {
    public:
        std::string id;
        int c, math, english;
        double avg;
        Rank ranks[4];

    public:
        Student(std::string id, int c, int math, int english) : id(move(id)), c(c), math(math), english(english) {
            avg = (c + math + english) / 3.0;
            ranks[0].code = "C";
            ranks[0].priority = 3; // C成绩的优先级为3
            ranks[1].code = "M";
            ranks[1].priority = 2; // 数学成绩的优先级为2
            ranks[2].code = "E";
            ranks[2].priority = 1; // 英语成绩的优先级为1
            ranks[3].code = "A";
            ranks[3].priority = 4; // 平均成绩的优先级为4
        }

        void sortRanks();

        Rank getBestRank();

        static bool compByC(const Student *stuA, const Student *stuB);

        static bool compByMath(const Student *stuA, const Student *stuB);

        static bool compByEnglish(const Student *stuA, const Student *stuB);

        static bool compByAvg(const Student *stuA, const Student *stuB);
    };

    /**
     * 思路：四个科目分为四个列表，在每个列表中都插入各个Student对象的指针，进行排序，从而找出每位学生每门学科的排名。
     * 将排名建模为Rank类，用priority成员量化科目排名的优先级；定义Rank::comp()函数，方便找出最好的排名。
     *
     * 可能的优化途径：将每个学生四门课的成绩存入一个数组，避免写重复代码。comp函数可以接收一个额外的整型参数，以实现依据不同科目排名。
     */
    static void solve();
};

#endif //PAT_EXERCISES_SORTING_H